export const state = {
	loginPopupShow: false, //控制是否打开登录弹窗
	loadingShow: false, //加载动画
	locateInformation: {}, //定位信息
	systemInfo: {}, // 系统信息
	loactionAddress: {}, //地址信息

	cityInfo: {}, //选择的城市信息

};
//缓存浏览器的数据名称
const cacheNameList = ["userInfo", 'loactionAddress', 'cityInfo'];
let clearTime;
export const mutations = {
	//取出缓存数据（打开APP就取出）
	setCacheData(state) {
		for (let name of cacheNameList) {
			let data;
			// #ifndef H5
			data = uni.getStorageSync(name);
			// #endif
			// #ifdef H5
			data = sessionStorage.getItem(name) || localStorage.getItem(name);
			// #endif
			if (data) {
				// #ifdef H5
				try {
					data = JSON.parse(data).data;
				} catch (e) {}
				// #endif
				state[name] = data;
			}
		}
	},
	setSystemInfo(state, data) {
		state.systemInfo = Object.assign({}, state.systemInfo, data);
	},

	setLoginPopupShow(state, data) {
		state.loginPopupShow = data
	},
	setLoadingShow(state, data) {
		state.loadingShow = data
	},
	setLocateInformation(state, data) {
		state.locateInformation = data
	},
	setLoactionAddress(state, data) {
		state.loactionAddress = data
	},
	setCityInfo(state, data) {
		state.cityInfo = data
		uni.setStorageSync('cityInfo', data);
	}



};
export const actions = {
	configList({
		commit
	}, codes) {
		return new Promise((resolve, reject) => {
			post({
				method: 'config.lists',
				codes: codes
			}).then(res => {
				let list = JSON.parse(res.data.lists[0].value)
				resolve(list)
			}).catch(error => {
				reject(error)
			})
		})
	},
};
export const getters = {
	// getHeaderBg: (state) => {
	// 	if (uni.getStorageSync('headerBg')) {
	// 		return uni.getStorageSync('headerBg')
	// 	} else {
	// 		var img = state.headerBg ? state.headerBg : ''
	// 		return img
	// 	}
	// }
}